<template>
	<view class="travelling_box">
		<view class="prompt dis_fx"  v-if="isOrderMan==0" >您本次最多可以选择 <view class="num">{{maxPeople}}</view> 位出行人</view>
		<view class="prompt dis_fx" v-if="isOrderMan==1" >选择一位预订人</view>
		<checkbox-group @change="selectMember">
			<view class="item dis_fx fx_column fx_between" v-for=" item in userList"  >
				<view>
					<view class="name">{{item.name}}</view>
					<view class="info">联系方式：{{item.mobilePhone}}</view>
					<view class="info">身份证号：{{item.idCard}}</view>
				</view>
				<label class="checkbox">
					<checkbox :value="item.id" :checked="item.checked"/>
				</label>
			</view>
		</checkbox-group>
		<view class="enter_btn" @click="sureMember" >确定</view>
	</view>
</template>

<script>
	import util from '../../common/util.js'
	export default {
		data() {
			return {
				userList:[],
				selectUser:[],
				maxPeople:0,
				isOrderMan:0,
			}
		},
		onLoad(option) {
			this.maxPeople=option.maxPeople
			this.isOrderMan=option.isOrderMan
		},
		onShow(){
			this.getStream()
			this.selectUser=[]
		},
		methods: {
			//选择随行人
			selectMember(e){
				var that=this;
				let agr=e.detail.value;
				let userList=that.userList;
				let selectUserd=[];
				
				for(var i in userList){
					let user=userList[i]
					for(var k in agr){
						var userId=agr[k]
						if(userId==user.id){
							user.checked=true;
							selectUserd.push(user)
						}
					}
				}
				
			
				that.selectUser=selectUserd;
				
				//console.log(selectUserd);
				
			},
			//确认
			sureMember(){
				
				
				
				var that=this;
				
				if(that.isOrderMan==1&&that.selectUser.length>1){
					uni.showModal({
						content: '只能添加一位预订人!',
						showCancel: false
					});
					return;
				}
				
				uni.$emit('getSelectMember',{memberList:that.selectUser,isOrderMan:that.isOrderMan})
				uni.navigateBack({
					delta: 1
				});
			},
			//获取出行人信息
			getStream(){
				uni.showLoading({
					mask:true,
					title: '加载中'
				});
				var that=this;
				var params={}
				util.fetchPost('/user/accompanier/list',params,function(res){
					let userList=res.data;
					for(var k in userList){
						userList[k].checked=false;
					}
					that.userList = userList;
					uni.hideLoading();
				},function(){},true)
			},
		}
	}
</script>

<style>
	.enter_btn{
		width:100%;
		height:98upx;
		background:rgba(255,200,0,1);
		color:rgba(51,51,51,1);
		font-size:36upx;
		line-height: 98upx;
		text-align: center;
		position: fixed;
		bottom: 0;
		left: 0;
	}
	.prompt{
		font-size: 30upx;
		color: #999;
	}
	.prompt .num{
		color: #FFC800;
		margin: 0 10upx;
	}
	.travelling_box{
		padding: 25upx;
	}
	.travelling_box .item{
		padding: 25upx 0;
		border-bottom: 1px solid #EAEAEA;
	}
	.travelling_box .item .name{
		font-size: 32upx;
		color: #333;
		font-weight: 600;
	}
	.travelling_box .item .info{
		font-size: 24upx;
		color: #999;
		margin-top: 20upx;
	}
</style>
